import { sampleSize, shuffle } from "lodash-es"
import request from "../request"

export const getFlowDataSources = () => {
    return request({
        url: '/portal/getFlowDataSources.json',
        data: { data: 'root' }
    })
}

export const getFlowTables = (data) => {
    return request({
        url: '/portal/getFlowTables.json',
        data
    })
}

export const getFlowColumns = (data) => {
    return request({
        url: '/portal/findColsInfo.json',
        data
    }).then(res => {
        // const d = data
        // const cnt = data?.namTable === 'as_asset_penetration_after' : 
        // debugger
        return {
            ...res,
            data: sampleSize(res.data, 5)
        }
    })
}

export const getFlowData = (data) => {
    return request({
        url: '/portal/getData.json',
        // data: {
        //     model: JSON.stringify(data)
        // },
        // type: 'post'
    }).then(res => {
        // debugger
        return {
            ...res,
            data: {
                ...res.data,
                data: shuffle(res.data.data),
            }
        }
    })
}